<html>
 <head>
    <script type='text/javascript' src='https://www.google.com/jsapi'></script>
    <script type='text/javascript'>
      google.load('visualization', '1', {packages:['gauge']});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Label');
        data.addColumn('number', 'Value');
        data.addRows(3);
        data.setValue(0, 0, 'Memory');
        data.setValue(0, 1, 0);
        data.setValue(1, 0, 'CPU');
        data.setValue(1, 1, 0);
        data.setValue(2, 0, 'Network');
        data.setValue(2, 1, 0);

        var chart = new google.visualization.Gauge(document.getElementById('chart_div'));
        var options = {width: 400, height: 120, redFrom: 90, redTo: 100,
            yellowFrom:75, yellowTo: 90, minorTicks: 5};
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
<?php

include('include/vm.php');

include 'include/Data.php';
    
$req = mysql_query('SELECT Id_machine, Nom_machine, Os_Type, Taille_Ram, Started FROM machine_virtuel WHERE Nom_machine = "'.$_GET['VM'].'" ORDER BY Nom_machine ASC');
$ligne = mysql_fetch_assoc($req);

$machine = htmlentities($_GET['VM']);

$vm = new vm($machine);

// Met le caractere : entre les différent octets de l addresse MAC
$mac = $vm->mac ;
$mac = substr_replace($mac,":",2,0);
$mac = substr_replace($mac,":",5,0);
$mac = substr_replace($mac,":",8,0);
$mac = substr_replace($mac,":",11,0);
$mac = substr_replace($mac,":",14,0);

//Converti les MAJUSCULES de l addresse MAC en minuscule  pour l adapter a la requete arp
$mac = strtolower($mac);

echo "<ol>
        <li>OS: $vm->os</li>
        <li>Ram: $vm->ram</li>
        <li>Adresse Mac: $mac</li>
        <li>Status: $vm->state</li>
	<li>Adresse IP: ";

        if ($ligne['Started'] == 1) 
	{
		echo exec("nmap 192.168.1.11-100 ; /usr/sbin/arp | grep '$mac' | awk '{print $1}'");
		echo "</li></ol>";
	}else {
		echo "none";
		echo "</li></ol>";
	}
?>
      <br><br><hr><br><br><H1>Indisponible pour le moment !!!</H1>
    <div id='chart_div'></div>
  </body>
</html>
